Google Go

推荐列表 站点导航

当前位置:首页 > 脚本编程 > Google Go >

Go语言配置文件解析器 类似于Windows下的INI文件.

来源:网络整理  作者:网友投稿  发布时间:2020-12-27 21:15
configPackageconfigisaConfigurationfileparserforINIformat包config是一个简洁方的,支持注释的Go语言配置文件解析器,类似于Windows下的...

Package config is a Configuration file parser for INI format

包 config 是一个简洁方的,支持注释的Go语言配置文件解析器,类似于Windows下的INI文件.

配置文件形式为[section] 的段构成, 内部使用 name=value键值对
如果为指定段节点,则默认放入名为[default]的段当中.
“#”为注释的开头,可以放置于任意的单独一行中.

安装 go get github.com/lxmgo/config 示例

请查看 conf.ini 文件作为使用示例

使用规范

示例配置文件:

[DEFAULT] host = act.wiki port = 8080 f64 = 64.1 [mysql] host = 127.0.0.1 [mongodb] host = 127.0.0.2 [redis] host = 127.0.0.3 push_key = key1,key2,key3,... [memcache] host = 127.0.0.4

加载配置文件:

config, err := NewConfig('testdata/testini.ini') c.Int('port') // result is int 8080 c.Int64('port') // result is int64 8080 c.Float64('f64') // result is float64 64.1 c.String('host') // result is string 'act.wiki' c.String('mysql.host') // result is string '127.0.0.1' c.String('redis.host') // result is string '127.0.0.3' c.Strings('redis.key') // result is []string{'key1','key2','key3',...} config APIS: String(key string) string Strings(key string) []string Bool(key string) (bool, error) Int(key string) (int, error) Int64(key string) (int64, error) Float64(key string) (float64,error) Set(key string, value string) error 更多信息 所有字符解析均使用小写的! 源码

https://github.com/lxmgo/config

相关热词: Go语言

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/go/9844.shtml

最新文章
Lisp进修Windows下面的开拓情 Lisp进修Windows下面的开拓情

时间:2021-01-12

Lisp进修Windows下面的开拓情 Lisp进修Windows下面的开拓情

时间:2021-01-12

为Go语言GC正名-2秒到1毫 为Go语言GC正名-2秒到1毫

时间:2020-12-27

go语言初探 一个helloworld编 go语言初探 一个helloworld编

时间:2020-12-27

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

Go语言配置文件解析器 类似于Windows下的INI文件.

2020-12-27 编辑:网友投稿

Package config is a Configuration file parser for INI format

包 config 是一个简洁方的,支持注释的Go语言配置文件解析器,类似于Windows下的INI文件.

配置文件形式为[section] 的段构成, 内部使用 name=value键值对
如果为指定段节点,则默认放入名为[default]的段当中.
“#”为注释的开头,可以放置于任意的单独一行中.

安装 go get github.com/lxmgo/config 示例

请查看 conf.ini 文件作为使用示例

使用规范

示例配置文件:

[DEFAULT] host = act.wiki port = 8080 f64 = 64.1 [mysql] host = 127.0.0.1 [mongodb] host = 127.0.0.2 [redis] host = 127.0.0.3 push_key = key1,key2,key3,... [memcache] host = 127.0.0.4

加载配置文件:

config, err := NewConfig('testdata/testini.ini') c.Int('port') // result is int 8080 c.Int64('port') // result is int64 8080 c.Float64('f64') // result is float64 64.1 c.String('host') // result is string 'act.wiki' c.String('mysql.host') // result is string '127.0.0.1' c.String('redis.host') // result is string '127.0.0.3' c.Strings('redis.key') // result is []string{'key1','key2','key3',...} config APIS: String(key string) string Strings(key string) []string Bool(key string) (bool, error) Int(key string) (int, error) Int64(key string) (int64, error) Float64(key string) (float64,error) Set(key string, value string) error 更多信息 所有字符解析均使用小写的! 源码

https://github.com/lxmgo/config

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/go/9844.shtml

相关文章

风云图片

推荐阅读

返回Google Go频道首页